package com.whfc.ms.api.sys.service.impl;

import com.whfc.common.file.FileHandler;
import com.whfc.common.file.FilePathConfig;
import com.whfc.common.util.RandomUtil;
import com.whfc.entity.dto.OssPathDTO;
import com.whfc.fuum.dto.SysRuleDTO;
import com.whfc.fuum.entity.SysUser;
import com.whfc.fuum.param.SysRuleAdd;
import com.whfc.fuum.param.SysRuleEdit;
import com.whfc.fuum.service.SysRuleService;
import com.whfc.ms.api.sys.service.MsSysRuleService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author qzexing
 * @version 1.0
 * @date 2020-12-10 19:39
 */
@Service
public class MsSysRuleServiceImpl implements MsSysRuleService {

    @DubboReference(interfaceClass = SysRuleService.class, version = "1.0.0")
    private SysRuleService sysRuleService;

    @Autowired
    private FileHandler fileHandler;

    @Autowired
    private FilePathConfig filePathConfig;

    @Override
    public List<SysRuleDTO> getRuleList(SysUser user, Integer platform) {
        return sysRuleService.getRuleList(user, platform);
    }

    @Override
    public List<SysRuleDTO> getDescendantList(Integer pid) {
        return sysRuleService.getDescendantList(pid);
    }

    @Override
    public void addRule(SysRuleAdd param) {
        sysRuleService.addRule(param);
    }

    @Override
    public void editRule(SysRuleEdit param) {
        sysRuleService.editRule(param);
    }

    @Override
    public void enableRule(Integer ruleId) {
        sysRuleService.enableRule(ruleId);
    }

    @Override
    public void disableRule(Integer ruleId) {
        sysRuleService.disableRule(ruleId);
    }

    @Override
    public void delRule(Integer ruleId) {
        sysRuleService.delRule(ruleId);
    }

    @Override
    public OssPathDTO uploadImg(MultipartFile file) throws Exception {
        String fileName = RandomUtil.getRandomFileName() + ".png";
        String ossKey = filePathConfig.getFilePath("sys/rule", fileName);
        String upload = fileHandler.upload(ossKey, file.getInputStream());
        return new OssPathDTO(upload);
    }
}
